package tt.lab.pmbok.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import tt.lab.pmbok.dto.InoutDTO;
import tt.lab.pmbok.dto.ProcessDTO;
import tt.lab.pmbok.dto.ToolDTO;
import tt.lab.pmbok.model.Inout;
import tt.lab.pmbok.model.PmbokProcess;
import tt.lab.pmbok.model.ProcessInout;
import tt.lab.pmbok.model.ProcessTool;
import tt.lab.pmbok.model.Tool;
import tt.lab.pmbok.service.InoutService;
import tt.lab.pmbok.service.ToolService;

@Controller
// 类似Struts的Action
public class ToolController {
	/**/
	@Resource(name = "toolService")
	private ToolService toolService; 


	@RequestMapping("/tool/{id}")
	public void retrieve(@PathVariable int id, Model model) {
		Tool tool = toolService.load(id);
		
		ToolDTO toolDTO = new ToolDTO(tool.getId(),tool.getName());
		for(ProcessTool processTool : tool.getSortedProcesses()){
			PmbokProcess process = processTool.getProcess();
			toolDTO.addProcess(new ProcessDTO(process.getId(), process.getName(),process.getPmbokId()));
		}
		model.addAttribute("tool", toolDTO);
	}

}